using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using umbraco.cms.businesslogic.media;
using Commerce.Common;

namespace CommerceForUmbraco.usercontrols
{
    public partial class ProductCrossSell : System.Web.UI.UserControl
    {
        protected DataTable dtCross;

        protected int _relatedProductID = 0;

        public string relatedProductID
        {
            get { return _relatedProductID.ToString(); }
            set { _relatedProductID = int.Parse(value); }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                if (_relatedProductID != 0)
                {
                    Commerce.Common.ProductCrossSellCollection crossSell = new ProductCrossSellCollection();
                    crossSell.Where("fromProductID", _relatedProductID);
                    crossSell.Load();

                    DataTable dt = crossSell.ToDataTable();

                    foreach (DataRow dr in dt.Rows)
                    {
                        int mediaId = int.Parse(dr["defaultImage"].ToString());
                        dr["defaultImage"] = new Media(mediaId).getProperty("umbracoFile").Value.ToString();
                    }

                    CrossSellProducts.DataSource = dt;
                    CrossSellProducts.DataBind();

                }
            }

        }

    }
}